import { getBcmDictName, getBcmDictList } from "../../../../hooks/bcmUseUntils";

const orderSureCancel = (orderItem, modalType, isOrderCancel, dealType, orderCancelReasonType, rejectReason, orderAction, showConfigModal=false) => {
    if (JSON.stringify(orderItem) != "{}") {
        let status = orderItem.orderStatus ? orderItem.orderStatus : orderItem     
            .afsOrderStatus,rejectReasonText = modalType == 'cancel' ? getBcmDictName('orderCancelReasonType',
                orderCancelReasonType) : modalType == 'rejectOrderCancelApply' ?
                getBcmDictName('rejectOrderCancelApplyType', orderCancelReasonType) : getBcmDictList(
                    'rejectReasonType').filter(a => a.pdict.indexOf(dealType) != -
                        1)?.find(a => a.value == orderCancelReasonType)?.text;
        switch (status) {
            case '1':
                if (isOrderCancel) {
                    return orderAction({
                        uniqueKey: '订单表',
                        methodName: 'cancelOrder'
                    }, orderItem, {
                        orderCancelReason: orderCancelReasonType == '999' ? 
                            rejectReason : rejectReasonText,
                        orderCancelReasonType: orderCancelReasonType
                    }, '取消订单操作成功', true);
                }
                return orderAction({
                    uniqueKey: '订单表',
                    methodName: 'manualRejectOrder'
                }, orderItem, {
                    orderCancelReason: orderCancelReasonType == '999' ? 
                        rejectReason : rejectReasonText,
                    orderCancelReasonType: orderCancelReasonType
                }, '拒单成功', true);
            case '6':
                if (isOrderCancel) {
                    return orderAction({
                        uniqueKey: '订单表',
                        methodName: 'cancelOrder'
                    }, orderItem, {
                        orderCancelReason: orderCancelReasonType == '999' ? 
                            rejectReason : rejectReasonText,
                        orderCancelReasonType: orderCancelReasonType
                    }, '取消订单操作成功', true);
                }
                return orderAction({
                    uniqueKey: '订单表',
                    methodName: 'rejectCancelApplyOrder'
                }, orderItem, {
                    orderCancelReason: orderCancelReasonType == '999' ? 
                        rejectReason : rejectReasonText,
                    orderCancelReasonType: orderCancelReasonType
                }, '驳回申请操作成功', true);
            case '10':
                return orderAction({
                    uniqueKey: '售后单表',
                    methodName: 'rejectAfsApplyOrder'
                }, orderItem, {
                    orderCancelReason: orderCancelReasonType == '999' ? 
                        rejectReason : rejectReasonText,
                    orderCancelReasonType: orderCancelReasonType,
                    afsOrderId: orderItem.afsOrderId
                }, '驳回申请操作成功', true);
            case '12':
                return orderAction({
                    uniqueKey: '售后单表',
                    methodName: 'afsRejectInBound'
                }, orderItem, {
                    orderCancelReason: orderCancelReasonType == '999' ? 
                        rejectReason : rejectReasonText,
                    orderCancelReasonType: orderCancelReasonType,
                    afsOrderId: orderItem.afsOrderId
                }, '驳回申请操作成功', true);
            case '17':
                return orderAction({
                    uniqueKey: '售后单表',
                    methodName: 'afsRejectInBound'
                }, orderItem, {
                    orderCancelReason: orderCancelReasonType == '999' ? 
                        rejectReason : rejectReasonText,
                    orderCancelReasonType: orderCancelReasonType,
                    afsOrderId: orderItem.afsOrderId
                }, '驳回申请操作成功', true);
            default:
                if (isOrderCancel) {
                    return orderAction({
                        uniqueKey: '订单表',
                        methodName: 'cancelOrder'
                    }, orderItem, {
                        orderCancelReason: orderCancelReasonType == '999' ? 
                            rejectReason : rejectReasonText,
                        orderCancelReasonType: orderCancelReasonType
                    }, '取消订单操作成功', true).then((response) => {
                        if (response?.afsOrderId && (!['2', '1'].includes(response?.syncErpBreakageStatus)) && status == '4' && showConfigModal) {
                            uni.navigateTo({
                                url: `/pages/BcmViews/PickingOrder/breakage?afsOrderId=` + response?.afsOrderId + '&type=2'
                            });
                        }
                    });
                }else{
                    return null
                }
        }
    }
}

export {
    orderSureCancel
}